#ifndef CAR_H
#define CAR_H

#include "my_ipc.h"
#include "tunnel.h"
#include <unistd.h> 
#include <sys/types.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>

typedef struct {
    char op[2];
    char content[100];
    int duration;
    int mid;
} CarOp;

typedef struct {
    int carid;
    Tunnel *tn;
    long int enter;
    CarOp *operation;
    int op_count;
    char car_mem[1000];
    int *read_p;
    int direction; // 0: 东向西, 1: 西向东
} Car;
#define TWO_WAY_TUNNEL // 定义宏，启用双向隧道

extern inline long int get_current_time();

Car* create_car(int carid, Tunnel *tn);
void read_from_maibox(Car *c, int mid, int length, int lasttime);
void write_to_mailbox(Car *c, char *context, int mid, int lasttime);
void exec_car(Car *c);

void enter_tunnel(Car *c); // 双向隧道
void leave_tunnel(Car *c, int i); // 双向隧道

#endif
